package com.jlkf.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jlkf.pojo.TblIntegralSet;
import com.jlkf.service.TblIntegralSetService;
import com.platform.server.response.response.pojo.ReturnData;
import com.platform.server.util.StringTools;

@Controller
@RequestMapping("integral")
public class IntegralController {
	@Autowired
	private TblIntegralSetService tblIntegralSetService;
	
	@RequestMapping("getDetail")
	@ResponseBody
	public ModelAndView getDetail(Integer type){
		TblIntegralSet integralSet = tblIntegralSetService.getDetailByType(type);
		ModelAndView andView = new ModelAndView();
    	andView.addObject("integral",integralSet);
    	andView.setViewName("jsp/integralManager/setIntegral");
    	return andView;
	}
	
	@RequestMapping("addOrUpdate")
	@ResponseBody
	private ReturnData addOrUpdate(@RequestBody String json){
		try{
			TblIntegralSet integralSet = StringTools.json2Obj(json, TblIntegralSet.class);
			int num = 0;
			if(integralSet.getgId()!=null){
				num = tblIntegralSetService.updateIntegral(integralSet); 
			}else{
				integralSet.setCreateTime(new Date());
				num = tblIntegralSetService.insertIntegral(integralSet);
			}
			if(num>0){
				return new ReturnData(200,"操作成功");
			}else{
				return new ReturnData(500,"操作失败");
			}
		}catch (Exception e) {
			e.printStackTrace();
			return new ReturnData(500,"系统错误");
		}
	}
}
